package com.mit.web.view.component.grid
{
	import com.mit.web.config.Constants;
	import com.mit.web.event.ClickGridCheckBoxEvent;
	import com.mit.web.vo.BaseVO;
	
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import mx.collections.ArrayCollection;
	import mx.controls.CheckBox;
	import mx.controls.DataGrid;

	public class GridCheckBoxHeader extends CheckBox
	{
		

		public function GridCheckBoxHeader()
		{
			super();
		}

		
		override protected function clickHandler(event:MouseEvent):void{
			super.clickHandler(event);
			
			var dg:DataGrid = DataGrid(listData.owner);
			var ds:ArrayCollection = ArrayCollection(dg.dataProvider);
			if(ds){
				for each(var o:Object in ds){
					
					o.isSelected = selected;
				}
				
				//Set hasSelected field
				//this.Data = GridCheckBoxColumn
				//Dispatch a event for the click
				dg.dispatchEvent(new ClickGridCheckBoxEvent(ClickGridCheckBoxEvent.GRID_CHECKBOX_CLICK));
			}
		}
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			var n:int = numChildren;
			for(var i:int = 0; i< n; i++){
				var c:DisplayObject = getChildAt(i);
				if(!(c is TextField)){
					c.x = Math.round((unscaledWidth - c.width) / 2);
					c.y = Math.round((unscaledHeight - c.height) / 2);
				}
			}
		}
	}
}